﻿Imports System.Data
Imports MyGeneration.dOOdads
Public Class rc_CostoActividad
    Private _MessageError As Exception = Nothing
    Public Property MessageError() As Exception
        Get
            Return _MessageError
        End Get
        Set(ByVal value As Exception)
            _MessageError = value
        End Set
    End Property


#Region "CostoActividad"

    Public Function Insert_CostoActividad(ByVal conn As String, ByVal codactividad As Integer, ByVal codproducto As Integer, ByVal codtipoemp As Integer, ByVal cantemp As Integer,
                                     ByVal canthora As Integer, ByVal costohoraact As Decimal, ByVal totalcostoact As Decimal) As Integer

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim costoactividad As New Class_RC_Data.Class_RC.COSTOACTIVIDAD(conn)

            costoactividad.AddNew()
            costoactividad.CodActividad = codactividad
            costoactividad.CodProducto = codproducto
            costoactividad.CodTipoEmp = codtipoemp
            costoactividad.CantEmp = cantemp
            costoactividad.CantHoras = canthora
            costoactividad.CostoHoraAct = costohoraact
            costoactividad.TotCostoAct = totalcostoact
            costoactividad.Save()

            tx.CommitTransaction()

            Return costoactividad.CodProducto

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return 0
        End Try

    End Function

    Public Function Update_CostoActividad(ByVal conn As String, ByVal codactividad As Integer, ByVal codproducto As Integer, ByVal codtipoemp As Integer,
                                     ByVal cantemp As Integer, ByVal canthora As Integer, ByVal costohoraact As Decimal, ByVal totalcostoact As Decimal) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim costoactividad As New Class_RC_Data.Class_RC.COSTOACTIVIDAD(conn)
            costoactividad.Where.CodProducto.Value = codproducto

            If costoactividad.Query.Load Then
                costoactividad.CodActividad = codactividad
                costoactividad.CodProducto = codproducto
                costoactividad.CodTipoEmp = codtipoemp
                costoactividad.CantEmp = cantemp
                costoactividad.CantHoras = canthora
                costoactividad.CostoHoraAct = costohoraact
                costoactividad.TotCostoAct = totalcostoact
                costoactividad.Save()
            End If

            tx.CommitTransaction()
            Return True
        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function Delete_CostoActividad(ByVal conn As String, ByVal codproducto As Integer, ByVal codactividad As Integer) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim costoactividad As New Class_RC_Data.Class_RC.COSTOACTIVIDAD(conn)
            costoactividad.Where.CodProducto.Value = codproducto
            costoactividad.Where.CodActividad.Value = codactividad

            If costoactividad.Query.Load Then
                costoactividad.MarkAsDeleted()
                costoactividad.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function get_CostoActividad_All(ByVal conn As String, ByVal codproducto As Integer) As DataTable
        Try
            '
            Dim vcostoactividad As New Class_RC_Data.Class_RC.VistaCostoActividad(conn)

            If codproducto > 0 Then

                vcostoactividad.Where.CodProducto.Value = codproducto
            End If
            If vcostoactividad.Query.Load Then
                If vcostoactividad.DefaultView.Table.Rows.Count > 0 Then
                    Return vcostoactividad.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_tipo_Empleado(ByVal conn As String) As DataTable
        Try
            Dim vTipoEmpleado As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)

            If vTipoEmpleado.Query.Load Then
                If vTipoEmpleado.DefaultView.Table.Rows.Count > 0 Then
                    Return vTipoEmpleado.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_Actividades(ByVal conn As String) As DataTable
        Try

            Dim vActividades As New Class_RC_Data.Class_RC.ACTIVIDADES(conn)

            If vActividades.Query.Load Then
                If vActividades.DefaultView.Table.Rows.Count > 0 Then
                    Return vActividades.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_categorias(ByVal conn As String, ByVal codtipoemp As Integer) As DataTable
        Try
            Dim vCategoria As New Class_RC_Data.Class_RC.CATEGORIAS(conn)
            vCategoria.Where.CodTipoEmp.Value = codtipoemp
            If vCategoria.Query.Load Then
                If vCategoria.DefaultView.Table.Rows.Count > 0 Then
                    Return vCategoria.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_promedio(ByVal conn As String, ByVal codtipoemp As Integer) As DataTable
        Try
            Dim vpromedio As New Class_RC_Data.Class_RC.VistaPromedio(conn)

            If vpromedio.Query.Load Then
                If vpromedio.DefaultView.Table.Rows.Count > 0 Then
                    Return vpromedio.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function
    

#End Region

End Class
